package cn.tedu.bonfire.front.payment.dao.persist.repository.impl;

import cn.tedu.bonfire.front.payment.dao.persist.mapper.UserMapper;
import cn.tedu.bonfire.front.payment.dao.persist.repository.IUserRepository;
import cn.tedu.bonfire.front.payment.pojo.entity.User;
import cn.tedu.bonfire.front.payment.pojo.entity.Withdrawal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public class UserRepositoryImpl implements IUserRepository {
    @Autowired
    UserMapper userMapper;

    @Override
    public int updateDalance(User user) {
        BigDecimal balance = userMapper.selectBalance(user.getId());
        user.setBalance(balance.add(user.getBalance()));
        return userMapper.updateById(user);
    }
    @Override
    public Long selectAuthorId(Long articleId) {
        return userMapper.selectUserId(articleId);
    }
    @Override
    public Integer selectExpiration(Long userId) {
        return userMapper.selectExpirationById(userId);
    }

    @Override
    public List<Long> selectAllExpirationGreaterThanZero() {
        return userMapper.listAllByExpirationGreaterThanZero();
    }



    @Override
    public int updateWithdrawal(Withdrawal withdrawal) {
        BigDecimal bigDecimal = userMapper.selectWithdrawal(withdrawal.getId());
        withdrawal.setAmount(bigDecimal.add(withdrawal.getAmount()));
        return userMapper.updateWithdrawal(withdrawal);
    }
}
